<template>
	<!-- 根据盘点单进行录入 -->
	<view class="">
		
		<form class="login-form">
			<view class="cu-form-group margin-top">
				<view class="title">盘点单号</view>
				<input  :value="mainTB.BILLNO" disabled ></input>
			</view>
			<view class="cu-form-group">
				<view class="title">集团名称</view>
				<input :value="mainTB.GROUPNAME" disabled ></input>
			</view>
			<view class="cu-form-group">
				<view class="title">组织名称</view>
				<input :value="mainTB.ORGNAME" disabled ></input>
			</view>
			<view class="cu-form-group">
				<view class="title">仓库</view>
				<input :value="mainTB.STORENAME || '' " disabled ></input>
			</view>
			<view class="cu-form-group">
				<view class="title">货区</view>
				<input :value="mainTB.ORGNAME" disabled @tap="searchFn('BA_ORGANIZE')"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">货架</view>
				<input :value="mainTB.ORGNAME" disabled @tap="searchFn('BA_ORGANIZE')"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">货层</view>
				<input :value="mainTB.ORGNAME" disabled ></input>
			</view>
			<view class="cu-form-group">
				<view class="title">货位</view>
				<input :value="mainTB.RACKNAME" disabled @tap="searchFn('BD_RACK')"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">备注</view>
				<input name="input"></input>
			</view>
			
		</form>
		
		<view class="mater-list">
			<view class="mater-item" v-for="item in materList">
				<view class="cu-form-group">
					<view class="title">
						名称：
					</view>
					<view >{{ item.VNAME || item.MATERIALNAME }}</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						规格：
					</view>
					<view >{{ item.MATSPEC  || '' }}</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						库存数量：
					</view>
					<view >{{ item.KNUM  || '' }} ({{ item.UNIT || '' }})</view>
				</view>
				<view class="cu-form-group">
					<view class="title">盘点数量</view>
					<input placeholder="盘点数量" v-model="item.NNUM" class="bottom-border"></input>
				</view>
			</view>
		</view>
		
		<view class="btn-area padding">
			<button hover-class="e-hover-btn" 
			 class="login-btn bg-blue"
			 @click="submitForm"
			 >
				提交
			</button>
		</view>
		
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import api from '@/common/api.js';
	import utils from '@/common/util.js'
	let _self, activeType;
	let query = {
			"category":"ST_INVENTORY",
			"page":1,
			"rows":"50",
			"sidx":"",
			"sord":"",
			"queryJson":{},
			"userId":"",
			"account":"admin"
	}
	export default {
		computed: mapState(['checkOrder','userInfo','baseUrl']),
		data(){
			return {
				list:[],
				materList:[],
				mainTB:{
					BILLNO:'',
					// 返回 PK_ORG(组织id),ORGNAME(组织名称), PK_STORE（仓库id），STORENAME（仓库名称）
					// PK_STATION(货位ID)，STATIONNAME（货位名称）:'',
					PK_GROUP:'',
					GROUPNAME:'',
					PK_ORG:'',
					ORGNAME:'',
					PK_STORE:'',
					STORENAME:'',
					PK_STATION:'',
					STATIONNAME:'',
					PK_RACK:'',
					RACKNAME:'',
					PK_INVER:'',
					INVER:'',
					account:'',
					userId:''
				}
			}
		},
		onLoad() {
			_self = this;
			_self.mainTB = {...this.checkOrder[0]};
			_self.mainTB.account = _self.userInfo.Account;
			_self.mainTB.userId  = _self.userInfo.UserId;
			_self.mainTB.INVER = _self.userInfo.Account;
			_self.mainTB.PK_INVER  = _self.userInfo.UserId;
			 console.log(JSON.stringify(this.checkOrder));
			 query.userId = _self.userInfo.UserId
			 query.account = _self.userInfo.Account
			 let tnt = { BILLNO:_self.mainTB.BILLNO }
			 query.queryJson = JSON.stringify(tnt);
			_self.getMaterList();
		},
		onShow() {
			uni.$on('getSelectItem',function(data){
				// console.log(data);
				// console.log(activeType);
				switch (activeType){
					case 'GROUP':
						_self.mainTB.GROUPNAME = data.FullName
						_self.mainTB.PK_GROUP = data.OrganizeId
						break;
					case 'BA_ORGANIZE':
						_self.mainTB.ORGNAME = data.FullName
						_self.mainTB.PK_ORG = data.OrganizeId
						break;
					case 'BA_DEPARTMENT':
						_self.mainTB.DEPTNAME = data.FullName
						_self.mainTB.PK_DEPT = data.OrganizeId
						break;
					case 'BD_RACK':
						_self.mainTB.RACKNAME = data.VNAME
						_self.mainTB.PK_RACK = data.BILLNO
						break;
					case 'BA_USER':
						_self.mainTB.APPLYER = data.RealName
						_self.mainTB.PK_APPLYER = data.UserId
						break;	
					case 'BD_STORE': // 仓库
						_self.mainTB.PK_STORE = data.BILLNO
						_self.mainTB.STORENAME = data.VNAME
						break;
					
						
					default:
						break;
				}
			})	
		},
		methods:{
			searchFn(t){
				activeType = t ;
				uni.navigateTo({
					url:'/pages/public/search?t='+t
				})
			},
			
			getMaterList(){
				console.log(query); 
				this.axios({
					url: api.apiPublic.getMaterList ,
					data: query ,
					isLoading: 1
				}).then(res=>{
					let { Result } = res ;
					let array = Result.rows || [];
					_self.materList = array
				})
			},
			
			
			submitForm(){
				let saveData = {..._self.mainTB,Detail:JSON.stringify(_self.materList) } ,
						saveURL = _self.baseUrl + api.apiPublic.checkListSubmit;
				this.axios({
					url: saveURL ,
					data: saveData ,
					isLoading: 1
				}).then(res=>{
					let { Result } = res ;
					utils.tips('提交成功')
					utils.delayBack();
				})
			}
		}
		
	}
</script>

<style scoped>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
	.mater-item{
		width: 680rpx;
		padding: 20rpx 10rpx;
		margin: 10rpx auto;
		background-color: #FFFFFF;
		border-radius: 16rpx;
	}
	.bottom-border{
		border-bottom: 1rpx solid #007AFF;
		text-align: right;
	}
</style>
